import matplotlib.pyplot as plt

import pandas as pd
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
import joblib

data = pd.read_csv("D:\daily work\ml\\test\\train_data8.csv")

data.dropna(inplace=True)

y1 = (data["y1"] / 0.002).astype(int) * 0.002
y2 = (data["y2"] / 0.002).astype(int) * 0.002

x = data.drop(["y1", "y2"], axis=1)

x_train, x_test, y_train, y_test = train_test_split(x, y1, test_size=0.2, random_state=0)

scaler = StandardScaler()

X_train = scaler.fit_transform(x_train)
X_test = scaler.transform(x_test)

r = {}
for depth in range(2, 21, 3):
    print("trading", depth)
    regr = DecisionTreeRegressor(max_depth=depth)
    scores = cross_val_score(regr, X_train, y_train, cv=10)
    r[depth] = scores


scores = []
depths = list(r.keys())
depths.sort()

for d in depths:
    scores.append(r[d].mean())
plt.plot(depths, scores, color="red", label="max_depth")
plt.legend()
#plt.savefig("D:\daily work\ml\\test\\cross_valid_scores_dtre_max_depth.png")
plt.show()
